﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.Script.Serialization;

namespace OrganizedIN.UI.Main
{
    public partial class Main : System.Web.UI.MasterPage
    {
        OIDataContext dc = new OIDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGroups();
                if (Session["UserID"] != null)
                {
                    hdnUname.Value = Session["UserID"].ToString();
                    var photo = (from d in dc.UserInformations
                                 where d.username == Session["UserID"].ToString()
                                 select d.ProfilePicture).SingleOrDefault();
                    if (photo != null && photo != "")
                    {
                        userImage.ImageUrl = photo;
                    }
                    else
                    {
                        userImage.ImageUrl = "~/images/user-icon.jpg";
                    }
                }
                else
                {
                    A7.Visible = false;
                    treemenu1.Visible = false;
                    loggedinTitle.Visible = false;
                    userImage.Visible = false;
                    uploadPhoto.Visible = false;
                }
            }
            lblusername.Text = Convert.ToString(Session["UserName"]);
        }

        private void BindGroups()
        {
            OIDataContext dc = new OIDataContext();
            var groups = (from d in dc.Group_Masters where d.User_Organizer_Mapping.username == Session["UserID"].ToString() select new { d.Group_Name, type = "Owner" }).Union(from d in dc.Group_Contact_Mappins where d.username == Session["UserID"].ToString() && d.Approved == true select new { d.Group_Master.Group_Name, type = "Member" });

        }
    }
}